﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;

namespace EcSalseManage.PageCommon
{
    public partial class ProjectDistrictSearch : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.ContentType = "text/xml";

            string strQuery;
            strQuery = Request.Form.Get("q");
            string strForm;
            strForm = Request.Form.Get("f");
            string strElem;
            strElem = Request.Form.Get("e");

            DataAccess.Operate.DA_Project_District_Inherit Project_District_Inherit = new DataAccess.Operate.DA_Project_District_Inherit();
            DataSet ds = new DataSet();

            ds = Project_District_Inherit.FindLibrary(Convert.ToInt32(strQuery));
            DataTable dtOptions = ds.Tables[0];


            StringBuilder strXML;
            strXML = new StringBuilder(@"<?xml version=""1.0"" ?>");
            strXML.Append("<selectChoice>");
            strXML.Append("<selectElement>");
            strXML.Append("<formName>" + strForm + "</formName>");
            strXML.Append("<formElem>" + strElem + "</formElem>");
            strXML.Append("</selectElement>");

            if (dtOptions.DefaultView.Count > 0)
            {

                strXML.Append("<entry>");
                strXML.Append("<optionText>--区--</optionText>");
                strXML.Append("<optionValue>-1</optionValue>");
                strXML.Append("</entry>");


                foreach (DataRowView drv in dtOptions.DefaultView)
                {
                    strXML.Append("<entry>");
                    strXML.Append("<optionText>" + drv.Row["District_Name"] + "</optionText>");
                    strXML.Append("<optionValue>" + drv.Row["District_ID"] + "</optionValue>");
                    strXML.Append("</entry>");
                }

            }

            strXML.Append("</selectChoice>");
            Response.Write(strXML.ToString());
        }
    }
}
